package cn.juque.jdfsystem.interceptor;

import cn.hutool.extra.spring.SpringUtil;
import cn.juque.jdfsystem.contants.BusinessConstants;
import cn.juque.jdfsystem.enums.ConfigCodeEnum;
import cn.juque.jdfsystem.helper.ConfigInfoHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>CheckSignatureInterceptor</li>
 * </ul>
 * @date 2023-01-11 16:03:56
 **/
@Slf4j
public class CheckSignatureInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        ConfigInfoHelper configInfoHelper = SpringUtil.getBean(ConfigInfoHelper.BEAN);
        String value = configInfoHelper.getConfigValue(ConfigCodeEnum.SIGNATURE.getCode());
        String code = request.getHeader(BusinessConstants.SIGNATURE);
        return value.equals(code);
    }
}
